package com.chenfan.filestore.utils.excel;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

import java.sql.Date;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;

public class SqlDateConverter implements Converter<Date> {
 
    @Override
    public Class<Date> supportJavaTypeKey() {
        return Date.class;
    }
 
    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }
    //date转为timestamp

    public WriteCellData<String> convertToExcelData(Date sqlDate, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration){
        return new WriteCellData<String>(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(sqlDate));
    }
}